<?php
include $this->Render('header.php');
?>
<link rel="stylesheet" type="text/css" href="<?php echo BASE_STYLE;?>/css/admin.css" />
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/common.js"></script>
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/uploadifive/jquery.uploadifive.js"></script>
<style type="text/css">
	.uploadifive-button {width:84px;height:84px !important;line-height:normal;margin-top:-84px;background:none !important;}
	
	.file-upload-completed,.uploadifive-queue-item {position:absolute;width:84px;bottom:0;}
	
	.uploadifive-queue-item .close {background: url('<?php echo BASE_STYLE;?>/uploadifive/uploadifive-cancel.png') 0 0 no-repeat;display: block;float: right;height: 16px;
text-indent: -9999px;width: 16px;}
	.uploadifive-queue-item .progress {height: 3px;margin-top: 5px;width: 100%;}
	.uploadifive-queue-item .progress-bar {background-color: #0072BC;height: 3px;width: 0;}
	
	.uploadifive-queue-item .filename {display:none;}
	input[type="text"],select {background:none;}
	.order-mianqian-load { padding:15px 10px;}
	body {overflow:scroll; overflow-x:hidden; min-width:600px !important;}
</style>
<script type="text/javascript">
window.BASE_URL = '<?php echo BASE_STYLE;?>';
</script>

<div class="tongrong-box" style="width:680px;">
	<form class="login-box-form J-ajaxForm" enctype="multipart/form-data" action="/orderedit/sign/option/signsave/" method="post" autocomplete="off">
	<div class="tongrong-box-main">
    	<table width="100%" cellpadding="0" cellspacing="0" border="0">
    	    <tr>
            	<td width="100px" height="30">修改申请要求人：</td>
                <td>
                	<select  <?php if($this->msg['o_ad_money']>0) {echo 'disabled="disabled"';}else{echo 'class="J-start"';} ?>  data-chkTxt="" name="start">
                    	<option>加载中...</option>
                    	 <?php if($this->msg['o_ad_money']>0) echo'<option value="1" selected="selected">主动</option>';?>
                    </select>
                </td>
            </tr>
        	<tr>
            	<td width="90px" height="30">所属板块：</td>
                <td>
                	<select class="J-base" data-chkTxt="" name="base">
                    	<option>加载中...</option>
                    </select>
                </td>
                <td width="90px" height="30">所属项目：</td>
                <td>
                	<select class="J-next" data-chkTxt="" name="next">
                    </select>
                </td>
            </tr>
            
            <tr class="J-base-val-td">
            	<td height="30">原　　值：</td>
                <td colspan="3">
                	<input type="text" name="base_val" class="J-base-val" style="width:455px;" value="<?php echo $this->data['base_val'];?>" readonly />
                </td>
            </tr>
            <tr>
            	<td height="30">新　　值：</td>
                <td colspan="3" class="J-now-val-td">
                	<input type="text" name="now_val" class="J-now-val" style="width:455px;" value="" />
                </td>
            </tr>
            
            <tr>
            	<td height="70">修改原因：</td>
                <td colspan="3">
                	<textarea name="up_reason" style="resize:none; width:455px;"></textarea>
                </td>
            </tr>
        </table>
    </div>
    <div class="luru-box-btn mt50" style="margin-right:70px;">
        <?php if($this->msg['o_ad_money']>0)  echo '<input type="hidden" name="start" value="type1" />';?>
		<input type="hidden" name="oid" value="<?php echo $this->oid;?>" />
    	<input class="btn-submit-blue fn-left mr15 J-submit" type="submit" value="提交" />
        <a class="a-btn-close J-a-btn-close" href="javascript:;">关闭</a>
    </div>
	</form>
</div>
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/dyhl_ext.js"></script>
<script> window.attachment = <?php echo json_encode($this->order['attachment']);?> ;
</script>
<script>


(function($){
	$.fn.NewdyhlSelect = function(options){
		var op = {url:'/orderedit/sign/option/ajaxkey/',callback:function(){}};
		options = $.extend({},op, options);
		var _that = $(this);
		
		$.post(options['url'],function(data){
			var html = '<option value="0">请选择</option>';
				if(data['success']){
					for(var i in data['type']){
						html+='<option value="'+i+'">'+data['type'][i]+'</option>';
					}
				}
	
			_that.html(html);
			
			new options['callback']();
			
		},'json');
		
	}
})(jQuery);

	$(".J-start").NewdyhlSelect({'url':'/orderedit/sign/option/ajaxkey/oid/<?php echo $this->oid;?>'});
	$(".J-start").on('change',function(){
		var startVal = $(this).val();
		if(startVal == 0){
			Ext.Msg.alert('请选择修改申请要求人!');
			return false;
		}
		$.post('/orderedit/sign/option/ajaxkey/oid/<?php echo $this->oid;?>',{"start":startVal},function(data){
			var html = '<option value="0">请选择</option>';
				if(data['success']){
					for(var i in data['type']){
						html+='<option value="'+i+'" data-type="'+data['type'][i][1]+'" data-txt="'+data['type'][i][2]+'">'+data['type'][i][0]+'</option>';
					}
				}
			$('.J-next').html(html);
				
		},'json');
	});


	//所属板块
	$(".J-base").dyhlSelectNew({'url':'/orderedit/sign/option/ajaxkey/oid/<?php echo $this->oid;?>'});
	$(".J-base").on('change',function(){
		var baseVal = $(this).val();
		if(baseVal == 0){
			Ext.Msg.alert('请选择所属板块！');	
			return false;
		}
		
		$.post('/orderedit/sign/option/ajaxkey/oid/<?php echo $this->oid;?>',{"base":baseVal},function(data){
			var html = '<option value="0">请选择</option>';
				if(data['success']){
					for(var i in data['data']){
						html+='<option value="'+i+'" data-type="'+data['data'][i][1]+'" data-txt="'+data['data'][i][2]+'">'+data['data'][i][0]+'</option>';
					}
				}
			$('.J-next').html(html);
				
		},'json');
	});
	//选择所属项目
	$('.J-next').on('change',function(){
		var _that = $(this).find('option:selected');
		var baseVal = $(".J-base").val();
		var nextVal = $(this).val();
		var nextTxt = $(this).text();
		var type = _that.attr('data-type'),
			txt = _that.attr('data-txt');
		//获取原值
		$.post('/orderedit/sign/option/ajaxkey/oid/<?php echo $this->oid;?>',{"base":baseVal,"next":nextVal},function(data){
			$(".J-base-val").val(data['data']);
		},'json');
		//生成新值框
		if(type == 1){//下拉选择
			$(".J-base-val-td").removeClass('fn-hide');//隐藏原值
			var html='<select class="J-now-val" name="now_val"></select>'; 
			$(".J-now-val-td").html(html); 
			if(nextVal == 'ot_pubbrand'){//是否公牌
			
				var shtml = '';
					shtml += '<option value="是">是</option>';
					shtml += '<option value="否">否</option>';
				$('.J-now-val').html(shtml);
			}else if(nextVal == 'ot_car_model'){
				/**
				** 重置之前的结构，用ext插件生成数据
				** 实现搜索功能
				**/
				$(".J-now-val-td").html('<input type="text" class="J-now-val" id="J-ot-car-model" style="height:22px;" name="now_val" />'); 
				//车型数据
				var  carModelStore = new Ext.data.Store({
						autoLoad:true,
						proxy:new Ext.data.HttpProxy({
							url:'/public/ajax/option/dictionary',
							method:'post'
						}),
						reader:new Ext.data.JsonReader({
							fields:['d_text','d_text']	
						}),
						baseParams:{
							type:txt	
						},
						remote:true
					});
				
				var order_ot_car_model_box = new Ext.form.ComboBox({
					store:carModelStore,
					forceSelection:true,
					blankText : '请选择',
					allowBlank: false,
					triggerAction:"all",
					mode:'local',
					displayField:'d_text',
					valueField:'d_text',
					applyTo:'J-ot-car-model',
				});
				
			}else {
				$('.J-now-val').dyhlSelect({"type":''+txt+''});
			}
		}else if(type == 3){//上传照片
			$(".J-base-val-td").addClass('fn-hide');//隐藏原值
			$(".J-now-val").attr({"type":"hidden"});//隐藏新值的输入框
			var html ='<dl class="mianqianxinxi-box" style="padding:10px 0;">';
				html+='	<dd style="position:relative;float:left;" class="mianqianxinxi-pic-list J-box-order-'+nextVal+'">';
				html+='		<div class="file-upload-box J-file-upload-box fn-left mr10">';
				html+='			<div class="file-upload-completed" id="J_'+nextVal+'"></div>';
				html+='			<img src="'+BASE_URL+'/images/btn_upload_pic.png" />';
				html+='			<input type="file" id="upload_'+nextVal+'" name="upload-pic" size="30" hidefocus="true" multiple="false" accept="image/*"/>';
				html+='		</div>';
				html+='</dd>';
				for(var i=0;i<attachment[nextVal].length;i++){
					html+='<div style="position:relative;display:inline-block; float:left;margin-right:10px;" class="item-box">';
					html+=' <em class="ico-close J-ico-close">';
					html+='</em>';
					html+=' <a href="'+attachment[nextVal+'_url'][i]+'" data-lightbox="pic" style="position:relative; display:inline-block; width:80px;height:80px;margin-right:10px;">';
					html+='<img class="example-image" src="'+attachment[nextVal+'_thurl'][i]+'" width="80" height="80"/>';
					html+='<input type="hidden" value="'+attachment[nextVal][i]+'" name="old[]" />';
					html+='</a></div>';
				}
				html+='</dl>';
				html+='<input type="hidden" name="now_val" class="J-now-val" style="width:455px;" value="" />';
			
			$(".J-now-val-td").html(html);
			
			render_upload();
				
		}else{//输入框
			$(".J-base-val-td").removeClass('fn-hide');//隐藏原值
			$(".J-now-val-td").html('<input type="text" name="now_val" style="width:455px;" value="" />');
		}
			
	});
	
	
	//关闭弹出
	$(".J-a-btn-close").on('click',function(){
		
		var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
		parent.Ext.getCmp(winElement.id).close();
		
	});
		$(".tongrong-box").on('click','.J-ico-close',function(){
		$(this).closest('div').remove();	
	});
	//删除上传的图片
	$(".J-now-val-td").on('click','.J-ico-close',function(){
		$(this).closest('a').remove();
		var path = $(this).siblings('img').data('path');
		
		var nowVal = $('.J-now-val').val();
		var newPath = '';
		if(nowVal !=''){
			var arr = nowVal.split(',');
			for(var i in arr){
				(function(i){
					if(arr[i] != path && typeof(arr[i]) != 'function' && arr[i] !=''){
						newPath += arr[i]+',';
					}	
				})(i);	
			}
			
			$('.J-now-val').val(newPath);
		}
		
			
	});
	
	$(document).ready(function(e) {
		//提交
        $(".J-submit").on('click',function(){
			$(this).dyhlForm({
				beforefunction:submitChk,
				nofunction:function(){
					$(".J-submit").prop('disabled',false);
					Ext.getBody().unmask();
				},
				sucessfunction:function(data){
					$(".J-submit").prop('disabled',false);
					Ext.getBody().unmask();
					if(data['success']){
						Ext.Msg.alert('提示','提交成功',function(){
							window.parent.App.store.reload();
							var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
							parent.Ext.getCmp(winElement.id).close();
						});
						
					}else{
						Ext.Msg.alert('提示',data['msg']);
					}
				}	
			});	
		});
    });
	
	//表单验证
	function submitChk(){
		if($(".J-base").val() == ''){
			Ext.Msg.alert('提示','请选择所属板块!');	
			return false;
		}
		
		if($(".J-next").val() == ''){
			Ext.Msg.alert('提示','请选择所属项目!');	
			return false;
		}
		
		$(".J-submit").prop('disabled',true);
		Ext.getBody().mask("数据提交中，请稍等");
	}
	
	<?php $timestamp = time();?>
var names = {'oa_cert':'.J-box-order-oa_cert','oa_assets':'.J-box-order-oa_assets','oa_singlecard':'.J-box-order-oa_singlecard','oa_family':'.J-box-order-oa_family','oa_sign':'.J-box-order-oa_sign','oa_video':'.J-box-order-oa_video','oa_flowing':'.J-box-order-oa_flowing','oa_other':'.J-box-order-oa_other','oa_contract':'.J-box-order-oa_contract'};
	function render_upload() {
		var key;
		for (key in names) {
			var fileTypeTxt = 'image/*';
        	var url = "/order/upfile/option/upimage/";
			if(key == 'oa_video'){
				var url="/order/upfile/option/video/";	
				fileTypeTxt = 'video/*';
			}
        	if(key == 'oa_singlecard'){
        	    limit = 5;
        	}else if(key == 'oa_contract'){
        	    limit = 100;
        	}else{
        	    limit = 20;
        	}
			$('#upload_' + key).uploadifive({
				'auto': true,
				'width': 84,
				'buttonText': '',
				'removeTimeout':1,
				'fileObjName':'upload-pic',
				'formData': {
					'timestamp': '<?php echo $timestamp;?>',
					'tb':key,
					'filebox':'upload-pic',
					'token': '<?php echo md5('unique_salt' . $timestamp);?>',
					'oid' : '<?php echo $this->order['base']['o_id'];?>'
				},
				'number': key,
				'queueClass':names[key],
				'uploadScript': url,
				'removeCompleted' : true,
				'uploadLimit'     : limit,
				'fileType'  : fileTypeTxt,
				'onSelect' : function(q, opt){
					//$('#'+opt.formData.key + opt.number).find('a').remove();
				},
				'onUploadComplete': function (file, data, opt) {
						var obj = $.parseJSON(data);
	
						if (data == 0) {
							Ext.Msg.alert('提示','您上传的文件不是允许的图片文件');
							return;
						};
						
						if(obj['success']){
							var html='';
								html+='<a href="javascript:;" style="position:relative; display:inline-block; width:84px;height:84px;margin-right:10px; margin-bottom:10px;">';
								html+='	<em class="ico-close J-ico-close"></em>';
								switch(opt.number){
									case 'oa_cert':
										html+='	<img class="example-image" data-path="'+obj['msg']['ai_path']+'" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
										pathUrl = obj['msg']['ai_path'];
										break;
									case 'oa_assets':
										html+='	<img class="example-image" data-path="'+obj['msg']['ai_path']+'" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
										pathUrl = obj['msg']['ai_path'];
										break;
									case 'oa_family':
										html+='	<img class="example-image" data-path="'+obj['msg']['ai_path']+'" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
										pathUrl = obj['msg']['ai_path'];
										break;
									case 'oa_sign':
										html+='	<img class="example-image" data-path="'+obj['msg']['ai_path']+'" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
										pathUrl = obj['msg']['ai_path'];
										break;
									case 'oa_flowing':
										html+='	<img class="example-image" data-path="'+obj['msg']['ai_path']+'" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
										pathUrl = obj['msg']['ai_path'];
										break;
									case 'oa_other':
										html+='	<img class="example-image" data-path="'+obj['msg']['ai_path']+'" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
										pathUrl = obj['msg']['ai_path'];
										break;
									case 'oa_contract':
										html+='	<img class="example-image" data-path="'+obj['msg']['ai_path']+'" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
										pathUrl = obj['msg']['ai_path'];
										break;
									case 'oa_video':
										html+='	<img class="example-image" data-path="'+obj['msg']['af_path']+'" src="<?php echo BASE_STYLE;?>/images/member/default_sildeshow.gif" width="80" height="80" />';
										pathUrl = obj['msg']['af_path'];
										break;	
									case 'oa_singlecard':
										html+='	<img class="example-image" data-path="'+obj['msg']['ai_path']+'" src="'+obj['msg']['thumb_path']+'" width="80" height="80" />';
										pathUrl = obj['msg']['ai_path'];
                                    break;
								}
								
								
								html+='</a>';
								
							var nowVal = $(".J-now-val").val();	
							nowVal += pathUrl+',';
							$(".J-now-val").val(nowVal);
							
							
							$(opt.queueClass).append(html);		
						}else{
							Ext.Msg.alert('提示',obj['msg']);
							return false;	
						}
	
				}
			});
		}
	};
	
</script>

<?php include $this->Render('footer.php'); ?>